package Thread;

public class Demo15 {
    private static int result=0; //借助result这样的成员变量来完成两个线程的数据交互
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(new Runnable() {
            int sum=0;
            @Override
            public void run() {
                for (int i = 1; i <=1000; i++) {
                    sum+=i;
                }
                result=sum;
            }
        });
        t1.start();
        t1.join();
        System.out.println("result="+result);
    }
}
